package com.cy.dda.comm.config;

import javax.annotation.PreDestroy;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.aliyun.oss.OSSClient;
import com.cy.dda.comm.properties.OssProperties;
import com.cy.dda.comm.utils.SpringContextUtils;

import lombok.extern.slf4j.Slf4j;

/**
 * 阿里云Oss配置
 *
 * @author: tanyilin
 * @create: 2018年10月26日 下午3:39:58
 */
@Slf4j
@Configuration
public class AliyunOssConfig {

	@Bean
	public OSSClient ossClient(OssProperties ossProperties) {
		OSSClient ossClient = new OSSClient(ossProperties.getEndpoint(), ossProperties.getAccessKeyId(), ossProperties.getSecretAccessKey());
		return ossClient;
	}
	
	@PreDestroy
	public void destroy() {
		log.info("正在关闭Oss...");
		OSSClient ossClient = SpringContextUtils.getBean(OSSClient.class);
		ossClient.shutdown();
		log.info("Oss已关闭");
	}
}
